<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace OSS\Model;

class CnameConfig implements XmlConfig
{
    private $cnameList = [];
    const OSS_MAX_RULES = 10;
    public function __construct()
    {
        $this->cnameList = [];
    }
    public function getCnames()
    {
        return $this->cnameList;
    }
    public function addCname($cname)
    {
        if(self::OSS_MAX_RULES <= count($this->cnameList)) {
            throw new \OSS\Core\OssException("num of cname in the config exceeds self::OSS_MAX_RULES: " . strval(self::OSS_MAX_RULES));
        }
        $this->cnameList[] = ["Domain" => $cname];
    }
    public function parseFromXml($strXml)
    {
        $xml = simplexml_load_string($strXml);
        if(!isset($xml->Cname)) {
            return NULL;
        }
        foreach ($xml->Cname as $entry) {
            $cname = [];
            foreach ($entry as $key => $value) {
                $cname[strval($key)] = strval($value);
            }
            $this->cnameList[] = $cname;
        }
    }
    public function serializeToXml()
    {
        $strXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<BucketCnameConfiguration>\n</BucketCnameConfiguration>";
        $xml = new \SimpleXMLElement($strXml);
        foreach ($this->cnameList as $cname) {
            $node = $xml->addChild("Cname");
            foreach ($cname as $key => $value) {
                $node->addChild($key, $value);
            }
        }
        return $xml->asXML();
    }
    public function __toString()
    {
        return $this->serializeToXml();
    }
}

?>